﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using Liguo.AppCode;
using DatabaseAccess;
using System.Data;

namespace Liguo.Administration
{

    public partial class Login : System.Web.UI.Page
    {
        SqlConnection con;
        private string adminID;
        private string pwd;
        SqlIt sqlit = new SqlIt();

        protected void Page_Load(object sender, EventArgs e)
        {

            adminID = Request["username"];
            pwd = Request["password"];

            if (adminID.Length > 0 && pwd.Length > 0)
            {
                DataSet ds = sqlit.SpecialItem("AdminInfo", "AdminName= " + "'" + adminID + "'", "*");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    String salt = ds.Tables[0].Rows[0]["Salt"].ToString();
                    //string adminlevel = ds.Tables[0].Rows[0]["AdminLevel"].ToString();
                    bool adminStatus = Convert.ToBoolean(ds.Tables[0].Rows[0]["Status"]);
                    if (adminStatus)
                    {
                        String md5Password = Utilities.GetMD5(pwd + salt);

                        if (md5Password.Equals(ds.Tables[0].Rows[0]["Password"].ToString()))
                        {
                            Response.Redirect("index.aspx");
                        }
                        else
                        {
                            Response.Write("<script>alert(\"密码错误\");</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert(\"管理员已停用！\");</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert(\"没有此账号名！\");</script>");
                }
            }
            else
            {
                Response.Write("<script>alert(\"请输入用户名或密码！\");</script>");
            }
            Response.Write("<script>top.location=\"LoginFrame.aspx\";</script>");
        }
    }
}



